<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>
	<link href="/admin/css/general.css" rel="stylesheet" type="text/css" />
	<link href="/admin/css/main.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="/admin/js/utils.js"></script>
	<script type="text/javascript" src="/admin/js/selectzone.js"></script>
	<script type="text/javascript" src="/admin/js/colorselector.js"></script>
	<script type="text/javascript" src="/admin/js/calendar.php?lang="></script>
  <script type="text/javascript" src="/admin/js/jquery.js"></script>
  <script charset="utf-8" src="/org/editor/kindeditor.js"></script>
  <script charset="utf-8" src="/org/editor/lang/zh_CN.js"></script> 
  <script>
        var editor;
        KindEditor.ready(function(K) {
          editor = K.create('textarea[name="goods_desc"]', {
            width:1115,
            height:390,
            resizeType : 1,
            allowImageUpload:true,
            allowPreviewEmoticons : false,
            items : [
             'fullscreen','source','|','fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
              'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
              'insertunorderedlist', '|', 'emoticons', 'image', 'link']
          });
        });
  </script>
  <script>
      $().ready(function(){
        $("input[name='auto_sn']").bind('click',function(){
            $("input[name='goods_sn']").hide();
            $(this).css('color','gray');
        })
      });
      function checkCat(obj){
          var top_cat_id_list = [{$top_cat_list}];
          for(var i=0;i<top_cat_id_list.length;i++){
            if(obj.value==top_cat_id_list[i]){
              alert('不能直接选择顶级栏目!');
              obj.value = 0;
              return false;
            }else if(obj.value == 0){
              alert('您还没有选择商品所属栏目!');
              return false;
            }
          }
          return true;            
      }
  </script>
</head>
<body>
<h1>
	<span class="action-span"><a href="{{url('manager/goods')}}">商品列表</a></span>
	<span class="action-span1"><a href="{{url('manager/main')}}">SHOP 管理中心 </a> </span>
	<span id="search_id" class="action-span1"> - 添加商品 </span>
	<div style="clear:both"></div>
</h1>

<div class="tab-div">

    <!-- tab bar -->
    <div id="tabbar-div">
      <p>
          <span class="tab-front" id="general-tab">商品通用信息</span>
      		<span class="tab-back" id="detail-tab">商品详细描述</span>
      		<span class="tab-back" id="image-tab">商品图片展示</span>
      </p>
    </div>
    <!-- tab body -->
    <div id="tabbody-div">
      <div style="text-align:center;font-size:20px;font-weight:bold;color:red">
        @if(count($errors)>0)
            @foreach($errors->all() as $err)
                {{$err}}
            @endforeach
        @endif
      </div>
      <form enctype="multipart/form-data" action="{{url('manager/goods')}}" method="post" name="theForm"> 
        <input type="hidden" name="MAX_FILE_SIZE" value="2097152">
		{{csrf_field()}}
		 <!-- 通用信息 -->
        <table width="90%" id="general-table" align="center" style="display: table;">
			<tbody>
				<tr>
					<td class="label">商品名称：</td>
					<td><input type="text" name="goods_name" value="{{old('goods_name')}}" size="30"><span class="require-field">*</span></td>
				</tr>
        <tr>
          <td class="label">商品货号：</td>
          <td><input  type="text" name="goods_sn" value="{{old('goods_sn')}}" size="30">
            <input type="button" name="auto_sn" value="自动生成"/>
            <span class="require-field">*</span></td>
        </tr>
			<tr>
				<td class="label">商品所属栏目：</td>

				<td>
					<select onchange="checkCat(this)" name="cat_id" onchange="hideCatDiv()">
						<option value="0">请选择商品栏目...</option>
                        @foreach($cat as $v)
							<option value="{{$v->cat_id}}">
                                {{str_repeat('▶',$v->level)}}{{$v->cat_name}}
							</option>
                        @endforeach
					</select>
                </td>

			</tr>
      <tr> 
        <td class="label">商品品牌</td>
        <td>

          <select name="goods_brand" id="">
              <option value="0">选择品牌...</option>
              @foreach($brand as $v)
                  <option value="{{$v->brand_id}}">{{$v->brand_name}}</option>
                  @endforeach
          </select>
        </td>
      </tr>
       <tr> 
        <td class="label">商品单位</td>
        <td>
          <select name="goods_unit" id="">
              <option value="0">选择商品单位...</option>
              @foreach($unit as $v)
            <option value="{{$v->unit_id}}">{{$v->unit_name}}</option>
                @endforeach
          </select>
        </td>
      </tr>
      <tr>
          <td class="label">
              商品状态:
         </td>
          <td>
              新品<input type="checkbox" value="1" name="goods_state[]"/>
              精品<input type="checkbox" value="2" name="goods_state[]"/>
              热销<input type="checkbox" value="3" name="goods_state[]"/>
          </td>
      </tr>
      <tr> 
        <td class="label">商品数量</td>
        <td>
          <input type="text" name="goods_number" value="{{empty(old('goods_number'))?0:old('goods_number')}}" />
        </td>
      </tr>
          <tr>
            <td class="label">市场售价：</td>
            <td><input type="text" name="market_price" value="{{empty(old('market_price')) ? 0 : old('market_price')}}" size="20">
            </td>
          </tr>
           <tr>
            <td class="label">本店售价：</td>
            <td><input type="text" name="shop_price" value="{{empty(old('goods_price'))?0:old('goods_price')}}" size="20">
            </td>
          </tr>
        </tbody></table>

        <!-- 详细描述 -->
        <table width="90%" id="detail-table" style="display: none;">
          <tbody>
          <tr>
          <td>
             <textarea name="goods_desc" id="" cols="30" rows="10">{{old('goods_desc')}}</textarea>
          </td>
          </tr>
        </tbody>
		</table>
		   <!-- 图片上传 -->
        <table width="90%" id="image-table" style="display: none;">
          <tbody>
          <tr>
            <td>
              <!--上传代码开始-->
              商品原图
               <input type="text" size="50" name="goods_ori">
                    <input id="file_upload" name="file_upload" type="file" multiple="true">
                    <script src="{{asset('org/uploadify/jquery.uploadify.min.js')}}" type="text/javascript">
                    </script>
                    <link rel="stylesheet" type="text/css" href="{{asset('org/uploadify/uploadify.css')}}">
                    <script type="text/javascript">
                        <?php $timestamp = time();?>
                        $(function() {
                            $('#file_upload').uploadify({
                                'buttonText' : '图片上传',
                                'formData'     : {
                                    'timestamp' : '<?php echo $timestamp;?>',
                                    '_token'     : "{{csrf_token()}}"
                                },
                                'swf'      : "{{asset('org/uploadify/uploadify.swf')}}",
                                'uploader' : "{{url('manager/upload')}}",
                                'onUploadSuccess' : function(file, data, response) {
                                    $('input[name=goods_ori]').val(data);
                                    $('#goods_ori_img').attr('src','/'+data);
                                }
                            });
                        });
                    </script>
                    <style>
                        .uploadify{display:inline-block;}
                        .uploadify-button{border:none; border-radius:5px; margin-top:8px;}
                        table.add_tab tr td span.uploadify-button-text{color: #FFF; margin:0;}
                    </style>
                    <img style="width:250px;" id="goods_ori_img" />
              <!--上传代码结束-->
            </td>
          </tr>
        </tbody>
		</table>
        <div class="button-div">
                    <input type="submit" value=" 确定 ">
          <input type="reset" value=" 重置 " class="button">
        </div>
      </form>
    </div>
</div>


<div id="footer">
	版权所有 &copy; 2012-2016
</div>
<script type="text/javascript" src="/admin/js/tab.js"></script>
<script type="text/javascript">
	function addImg(obj){
      var src  = obj.parentNode.parentNode;
      var idx  = rowindex(src);
      var tbl  = document.getElementById('gallery-table');
      var row  = tbl.insertRow(idx + 1);
      var cell = row.insertCell(-1);
      cell.innerHTML = src.cells[0].innerHTML.replace(/(.*)(addImg)(.*)(\[)(\+)/i, "$1removeImg$3$4-");
  	}

    function removeImg(obj){
      var row = rowindex(obj.parentNode.parentNode);
      var tbl = document.getElementById('gallery-table');
      tbl.deleteRow(row);
  	}

   	function dropImg(imgId){
    	Ajax.call('goods.php?is_ajax=1&act=drop_image', "img_id="+imgId, dropImgResponse, "GET", "JSON");
  	}

  	function dropImgResponse(result){
      if (result.error == 0){
          document.getElementById('gallery_' + result.content).style.display = 'none';
      }
  	}

</script>
</body>
</html>